/********************************************************************
***	Author : Franck Tomeba - Domenico DE FANO
*** 	Coprocessor Simulation 2
***	Do 3 monitoring round and at each round
***	Read and print the results stored in the result buffer
***
********************************************************************/
#include "TestApp.h"
#include "stdio.h"

int main(void)
{
	int round=3, i;
	unsigned int value;
	putnum(XPAR_COPRO_FINAL_0_DEVICE_ID);	
	
	
	print("\r\nCoprocessor Simulation 1");
	print("\r\nDo 3 monitoring round and result 4 result buffer registers ");


	print("\r\nStart Monitoring");
	write_reg(OFFSET_CMD, CMD_RESET);
	write_reg(OFFSET_CMD, CMD_NOP);
	
	print("\r\nSet Monitoring Length : 0x1B");
	write_reg(OFFSET_MON_LEN, 0x00000027);
	putnum(read_reg(OFFSET_MON_LEN));
	
	print("\r\nSet Scan Period : 0x0FFFFFFF");
	write_reg(OFFSET_SCAN_PERIOD, 0x0fffffff);
	putnum(read_reg(OFFSET_SCAN_PERIOD));
	
	print("\r\nSet Gateway Configuration String : 0x05");
	write_reg(OFFSET_GW_CONFIG, 0x00000007);
	putnum(read_reg(OFFSET_GW_CONFIG));
	
	print("\r\nSet Configuration Buffer 1 : 0x12345678");
	write_reg(OFFSET_CONFIG_BUFFER_1, 0xffffffff);
	putnum(read_reg(OFFSET_CONFIG_BUFFER_1));
	
	print("\r\nSet Configuration Buffer 2 : 0xFEDCBA98");
	write_reg(OFFSET_CONFIG_BUFFER_2, 0x00000000);
	putnum(read_reg(OFFSET_CONFIG_BUFFER_2));
	
	print("\r\nSet Configuration Buffer 3 : 0x76543210");
	write_reg(OFFSET_CONFIG_BUFFER_3, 0x00000000);
	putnum(read_reg(OFFSET_CONFIG_BUFFER_3));

	print("\r\nStart Monitoring");
	write_reg(OFFSET_CMD, CMD_START);
	write_reg(OFFSET_CMD, CMD_NOP);	
	for ( i=0; i<3; i ++ ) {
	print("\r\nRound ");
	putnum(i);
	

	
	print("\r\nBusy Waiting on Interrupt");
	value = 0;
		do {
			value = read_reg(OFFSET_IRQ);
			print("\n\rIRQ Reg :");
			putnum(value);
			
			value = read_reg(OFFSET_STATUS);
			print("\n\rSTATUS : ");
			putnum(value);
		} while ( value == 0 );
		
		print("\r\nResult Buffer 1 : ");
		putnum(read_reg(OFFSET_RESULT_BUFFER_1));
		
		print("\r\nResult Buffer 2 : ");
		putnum(read_reg(OFFSET_RESULT_BUFFER_2)); 
		
		print("\r\nResult Buffer 3 : ");
		putnum(read_reg(OFFSET_RESULT_BUFFER_3)); 

		print("\r\nResult Buffer 4 : ");
		putnum(read_reg(OFFSET_RESULT_BUFFER_4)); 
		
		print("\r\nAcknowledge the interrupt");
		write_reg(OFFSET_IRQ, 0);

	}
	
	print("\r\nStop Monitoring");
	write_reg(OFFSET_CMD, CMD_STOP);
	write_reg(OFFSET_CMD, CMD_NOP);

	return 1;
}
